package com.yoyo.yyadsdk.util;


import androidx.annotation.NonNull;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Random;

public class TimeUtils {

    public static final long SECOND = 1000;
    public static final long MINUTE = 60 * SECOND;
    public static final long HOUR = 60 * MINUTE;
    public static final long DAY = 24 * HOUR;

    public static Integer getHHmm() {
        try {
            return Integer.valueOf(new SimpleDateFormat("HHmm", Locale.getDefault()).format(new Date()));
        } catch (Exception ignore) {
            return null;
        }
    }

    public static String getTime() {
        try {
            return new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date());
        } catch (Exception ignore) {
            return "";
        }
    }

    @NonNull
    public static String getDate() {
        try {
            return new SimpleDateFormat("MM月dd日", Locale.getDefault()).format(new Date());
        } catch (Exception ignore) {
            return "";
        }
    }

    @NonNull
    public static String getDate(String pattern) {
        try {
            return new SimpleDateFormat(pattern, Locale.getDefault()).format(new Date());
        } catch (Exception ignore) {
            return "";
        }
    }

    public static boolean isToday(long time) {
        long timeMillis = System.currentTimeMillis();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        String sp_time = sf.format(time);
        String current_time = sf.format(timeMillis);
        return sp_time.equals(current_time);
    }

    public static long getDay() {
        long timeMillis = System.currentTimeMillis();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
        String sp_time = sf.format(timeMillis);
        try {
            return sf.parse(sp_time).getTime();
        } catch (ParseException ignored) {
            return 0;
        }
    }

    public static String getWeek(int week) {
        switch (week) {
            case 1:
                return "星期日";
            case 2:
                return "星期一";
            case 3:
                return "星期二";
            case 4:
                return "星期三";
            case 5:
                return "星期四";
            case 6:
                return "星期五";
            default:
                return "星期六";
        }
    }
}
